import time
import sys
import json
sys.path.append(r'.')
from DrissionPage import ChromiumPage


def load_param_datas_from_file(file_path):
    with open(file_path, "r", encoding='utf-8') as f:
        json_file_datas = json.loads(f.read())    # load的传入参数为字符串类型
        return json_file_datas

def run_rpa_from_json_file():
    json_file_datas = load_param_datas_from_file('sycm_trend_star.data.json')
    port = json_file_datas['port']
    url = json_file_datas['url']
    saveFile = json_file_datas['saveFile']
    page = ChromiumPage(addr_or_opts= '127.0.0.1:' + str(port))
    page.get(url)
    # 等待页面加载
    page.wait.load_start()
    # 滚动到最底部
    page.scroll.to_bottom()
    time.sleep(1)
    # 下载页面
    html_body = page.ele('tag:body')
    with open(saveFile, "w", encoding='utf-8') as file:
        file.write(html_body.html)
    # 滚动到某个已获取到的元素

run_rpa_from_json_file()



